/**
 * markdown 链接生成 json 数据
 */
const fs = require('fs');

const lines = fs.readFileSync('../../../markdown/灵感创意/建站系统.md').toString().split("\n");
let list = [], text = '', items = [], isStart = false;
lines.forEach(line => {
    if (isStart) {
        let match = line.match(/\[([^\]]+)\]\(([^\)]+)\)/);
        if (match) {
            items.push({ text: match[1], link: match[2] })
        }
    }
    if (line.startsWith('### ')) {
        if (text.length > 0 && items.length > 0) {
            let data = {
                text,
                data: items
            }
            list.push(data);
        }
        isStart = true;
        text = line.substring(4).trim();
        items = [];
    }
})
fs.writeFileSync('./makejson.json', JSON.stringify(list));
console.log('All donw.');